<template>
  <div class="pro_con">
    <el-card class="box-card">
      <div class="clearfix">
        <i class="iconfont icon-sousuo-copy"> </i>
        <span> 添加商品分类</span>
      </div>
    </el-card>

    <el-form :model="listQuery" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="编号:" prop="name">
        <el-input v-model="listQuery.name"></el-input>
      </el-form-item>

       <el-form-item label="类型名称:" prop="name">
        <el-input v-model="listQuery.name"></el-input>
      </el-form-item>
      <el-form-item label="属性数量:" prop="attribute_count">
        <el-input v-model="listQuery.attribute_count"></el-input>
      </el-form-item>
     
    

      <el-form-item label="参数数量:" prop="param_count">
        <el-input v-model="listQuery.param_count"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">立即添加</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>


  </div>
</template>
<script>
import {xglx2} from "@/api/product.js";
export default {
  name: "productAttrAdd",
  data() {
    return {
      listQuery: {
      
        name:"",//名称
        attribute_count:0,//属性数量
        param_count:0 //参数数量
      },
      rules: {
        // name: [
        //   { required: true, message: "请输入商品分类名称", trigger: "blur" },
        //   {
        //     min: 3,
        //     max: 100,
        //     message: "长度在3-100个字符之间",
        //     trigger: "blur",
        //   },
        // ],
      },
      productCateOptions:[],//上级分类的数据
      
    };
  },
  created(){
    this.tjfl22(),
     getProductOne3({ id: this.$route.params.id }).then((res) => {
      console.log(res);
      this.listQuery = res.data;
    });

  },
  methods: {
    tjfl22:async function(){
      const res = await tjfl1();
      console.log(res);
    },

    //添加商品分类
    submitForm: function (formName) {
      console.log("表单提交了");
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if(this.listQuery.parent_id !=0){
            this.listQuery.level=1;
          }
          //表单验证通过
          console.log("表单验证通过", this.listQuery);
          //调用后台接口将数据传给 服务器，生成一条新的数据
          xglx2(this.listQuery).then((res) => {
            console.log(res);
            if (res.msg == "添加成功") {

              this.$message({
                message: "成功添加商品分类",
                duration: 1000,
                type: "success",
              });
              this.$router.push("/pms/productAttr");
            }
          });
        } else {
          console.log("表单验证没通过");
          return false;
        }
      });
    },
  },
};
</script>
<style scoped lang="scss">
.pro_con {
  padding: 10px;
  .box-card {
    margin-bottom: 10px;
  }
}
</style>